package com.activenetwork.util.grid.condition;

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class RecordCheckboxAttributeCondition implements Condition {
	
	private int column;
	private String attr;
	private String value;
	
	public void setColumn(int column) {
		this.column = column;
	}
	
	public void setAttr(String attr) {
		this.attr = attr;
	}
	
	public void setValue(String value) {
		this.value = value;
	}
	
	/**
	 * Empty constructor
	 */
	public RecordCheckboxAttributeCondition() {
		this.column = -1;
		this.attr = null;
		this.value = null;
	}
	
	/**
	 * Direct constructor
	 * 
	 * @param column
	 * @param attr
	 * @param value
	 */
	public RecordCheckboxAttributeCondition(int column, String attr, String value) {
		this.column = column;
		this.attr = attr;
		this.value = value;
	}
	
	@Override
	public boolean matchs(WebElement row) {
		boolean flag = false;
		String attrValue = row.findElement(By.xpath("./td[" + column + "]//input[@type='checkbox']")).getAttribute(attr).trim();
		if (StringUtils.containsIgnoreCase(attrValue, value)) {
			flag = true;
		}
		return flag;
	}
	
}
